Dreamweaver Article

Macromedia - Developer Center: Creating a Flash Element


Table of Contents

  1. Introduction
  2. Preparing a Flash Component for a life as a Flash Element
    1. Single Quotes
    2. Placement of [Inspectable] tags
    3. Type setting for links
    4. Defining the type for Array elements
    5. Further documentation
    6. Updating the FooterNav component
    7. Exporting the FooterNav component as Flash Element
  3. Creating the Extension
    1. Setting up the Extension Installation File
    2. Compiling the Extension
    3. Installing the Extension
    4. Using the Footer Nav Extension

Creating the Extension

Now that you have created the Flash element, you need to get it into Dreamweaver. The best way to do this is to create an extension, which will take care of both placing the SWC file in the proper location and adding it to the Dreamweaver Insert menu. You then use the Extension Manager to install your extension, and you can choose to share it with others using the Macromedia Exchange.

Macromedia has created some extensive documentation on how to create an extension for any of their products at http://download.macromedia.com/pub/exchange/mxi_file_format.pdf, and in particular how to extend Dreamweaver at http://www.macromedia.com/support/documentation/en/dreamweaver/. The documentation is a great reference if you want to dive into this deeper. To merely get started, it is a tad bit too extensive, however.

What you will use is a simple template for a Flash element extension that you can modify for your own Flash elements. Thanks go to Winsha Chen from the Dreamweaver engineering team for helping me to put this together.

You need the following in order to create an extension:

  • The Extension Manager (EM).
    The EM not only takes care of installing (and removing) your extensions, but also creates them. You should have it installed by now. If not, get it at: www.macromedia.com/exchange/em_download/
  • The files that make up your extension.
    In our case, that will be just one file, FooterNav.swc. You already have that.
  • An extension installation file.
    This is an XML file with an .MXI file suffix containing the instructions on how to install the extension. That’s the missing piece; I will get to it in a moment.

Setting up the Extension Installation File

Open the extension installation file. It is in XML format, but of course in a special format for the Extension Manager. The following is the complete file—save it as FooterNav.mxi; it’s also included with the files for this article. I will go over each section with you. You can find additional and more extensive documentation in the documents listed above.

Note: XML files are a bit more finicky with regards to proper syntax than HTML you write for a browser. It is a good idea to start working from a template, rather than writing it from scratch. Also as a quick tip—to test your syntax, rename the file with an XML extension and open it in Internet Explorer or Mozilla. The built-in XML parser in these browsers will either display the XML in a tree form or tell you where it found errors.

<macromedia-extension
	 name="Footer Nav Flash Element"
	 version="1.0"
	 type="FlashElement"
	 requires-restart="true">

	<author name="Andreas Heim" />

	<products>
		<product name="Dreamweaver" version="7" primary="true" />
	</products>

	<description>
	<![CDATA[
	This Extension installs a Flash Element (FooterNav.swc) into the User Config\Objects\FlashElements\ folder. 
	]]>
	</description>

	<ui-access>
	<![CDATA[
	Access the Footer Nav Flash Element by selecting Flash Elements in the Insert Bar, then clicking the Footer Nav button.<br><br>
	You can also access it by selecting Insert -> Media -> Footer Nav
	]]>
	</ui-access>

	<files>
		<file source="FooterNav.swc" destination="$dreamweaver\Configuration\Objects\FlashElements\" />
	</files>

	<configuration-changes>
		<menu-insert insertAfter="DWMenu_Insert_Media_ImageViewer">
			<menuitem id="DWMenu_Insert_FlashElement_FooterNav" name="Footer Nav" key="" command="dw.getDocumentDOM().insertFlashElement('FooterNav.swc')" enabled="(dw.getFocus() != 'browser') && (dw.getDocumentDOM() != null &&
dw.getDocumentDOM().getParseMode() == 'html')"
 />
		</menu-insert>
		<insertbar-changes>
			<insertbar-item-insert insertAfter="FLT_imageViewer">
				<button id="FlashElement_FooterNav" name="Footer Nav" file="FlashElements\FooterNav.swc" command="dw.getDocumentDOM().insertFlashElement('FooterNav.swc')" /> 
			</insertbar-item-insert>
		</insertbar-changes>
	</configuration-changes>
</macromedia-extension>

Now look at this element by element.

<macromedia-extension
  name="Footer Nav Flash Element"
  version="1.0"
  type="FlashElement"
  requires-restart="true">

It’s pretty straightforward to define the name, type and version of the extension. The EM uses the type to categorize it and also displays an icon for it. This extension changes some configuration files of Dreamweaver, so it will only become active after you start the application the next time.

<author name="Andreas Heim" />

That will be you!

<products>
	<product name="Dreamweaver" version="7" primary="true" />
</products>

You can install an extension for multiple products, so you need a separate tag for it. Here, you define Dreamweaver as the only product, require at least version 7 (MX 2004), and ensure it actually installs there, even if you have a later version installed.

<description>
<![CDATA[
This Extension installs a Flash Element (FooterNav.swc) into the User Config\Objects\FlashElements\ folder. 
]]>
</description>

<ui-access>
<![CDATA[
Access the Footer Nav Flash Element by selecting Flash Elements in the Insert Bar, then clicking the Footer Nav button.<br><br>
You can also access it by selecting Insert -> Media -> Footer Nav
]]>
</ui-access>

These two fields contain what is displayed in the bottom description field in the EM when you select the extension. The first one is simply a description; the second one is intended to tell the user how to get to the extension. The <![CDATA[ ]]> tag has a special function in XML: It tells the parser to ignore anything inside and just pass it as-is as a text node. This means, for example, you can use HTML formatting here such as inserting line breaks with <br> and you also don't have to worry about encoding special characters. In other words—it makes your life easier. Don’t take it out.

<files>
<file source="FooterNav.swc" destination="$dreamweaver\Configuration\Objects\FlashElements\" />
</files>

This section tells the EM what files to include with the extension and where to place them. You can list multiple files. In this case, you only have one Flash Element to install. The source path is relative to the path of the MXI file. Please note that $dreamweaver in the destination path is not where the application is installed, but rather your personal configuration folder.

<configuration-changes>

	<menu-insert insertAfter="DWMenu_Insert_Media_ImageViewer">
		<menuitem id="DWMenu_Insert_FlashElement_FooterNav" name="Footer Nav" key="" command="dw.getDocumentDOM().insertFlashElement('FooterNav.swc')" enabled="(dw.getFocus() != 'browser') && (dw.getDocumentDOM() != null &&
dw.getDocumentDOM().getParseMode() == 'html')"
 />
	</menu-insert>
	
<insertbar-changes>
		<insertbar-item-insert insertAfter="FLT_imageViewer">
			<button id="FlashElement_FooterNav" name="Footer Nav" file="FlashElements\FooterNav.swc" command="dw.getDocumentDOM().insertFlashElement('FooterNav.swc')" /> 
		</insertbar-item-insert>
	</insertbar-changes>

</configuration-changes>

This is the tricky part of the installation file. First you defined all the settings for EM, then placed your files; now, you are changing the Dreamweaver configuration to add the Footer Nav Flash Element in two different places.

Although it seems complicated, it is quite self-explanatory. The first tag <menu-insert> adds the Flash element to the Insert/Media menu, after the Image Viewer Flash element. Nested, the Footer Nav is listed as an actual menu item. The name attribute defines what you see displayed; the id is a unique identifier, so it can be addressed. Next, there is a command attribute that looks a lot like JavaScript. Well, it actually is JavaScript. Dreamweaver is entirely extensible and controllable through a JavaScript API. Pretty much anything you do in Dreamweaver has a corresponding JavaScript command. So what you see defined here is the code to execute once the end user clicks the menu item.

dw.getDocumentDOM().insertFlashElement('FooterNav.swc')

This tells Dreamweaver to take the current document, (getDocumentDOM()) and insert our ('FooterNav.swc') Flash Element (insertFlashElement). If you look at it that way, it seems quite logical. You can learn more details about this in the Extending Dreamweaver documentation.

Finally, there is a very cryptic looking enabled attribute. It defines when the menu item will be active and when grayed out. It makes sure that you can insert the Flash element only in an open document that can be parsed as HTML. For example if you do not have any document open, there is no place to insert the Flash element, so the menu item is unavailable. There is also an empty key attribute; you can use it to define a keyboard shortcut.

The second part, <insertbar-changes>, looks very familiar. The differences are because the Insert bar does not function the same as the Insert menu. It doesn't need an enable attribute, since the insert bar is automatically enabled or disabled based on the context. At the core, it still means defining where to insert the Flash element into the bar, what to display, and what code to execute when a user clicks it.

Compiling the Extension

All the ingredients for the Extension are ready—it is time to put them together. At this point, you should have FooterNav.swc and FooterNav.mxi in the same folder.

  1. Open the Extension Manager (EM).
  2. From the File menu, choose Package Extension.
  3. Navigate to the folder where you placed FooterNav.mxi, select the file and click ok.
  4. You will be asked to save the extension. FooterNav.mxp will already be set as name. Click Save.

A confirmation dialog box informs you that the Extension was created successfully. When you create your own extension installation files, you may sometimes get error messages and you will have to correct your file.

Note: You can also double-click FooterNav.mxi to launch the EM and start the packaging process.

Installing the Extension

You created the extension, now you will want to install it and try it out.

  1. Close Dreamweaver if you have it open.
  2. Go back to the Extension Manager (EM).
  3. From the File menu, select Install Extension.
  4. Navigate to FooterNav.mxp, select it, and click Install.
  5. You will be greeted with a Extension Disclaimer dialog box. I recommend reading it before clicking Accept.

After clicking Accept, the Extension installs and confirms that the installation was successful.

The Extension Manager successful install dialog box

Figure 1. The Extension Manager successful install dialog box

Note: You can also double-click FooterNav.mxp to install it.

The Extension Manager showing the Footer Nav Flash Element

Figure 2. The Extension Manager showing the Footer Nav Flash Element

Using the Footer Nav Extension

After creating and installing the Extension, you will want to see it in action.

  1. Open Dreamweaver. If you didn't close it before installing the extension, you will have to restart it.
  2. Create a new HTML document, save it, and switch to the Design view. It is important that you save it.
  3. Open the Insert menu, find the Media nested menu. Underneath Image Viewer, see the Footer Nav. Click it to insert it. You can also find Footer Nav in the Flash Elements Insert Bar.
  4. Specify a file name for the Flash Element.
  5. The Footer Nav is now in your document, displayed as a gray box with a Flash logo.
  6. The Tag inspector will open automatically. Specify the parameters for the Flash element just as you would specify the component parameters in Flash MX 2004. Try it out!
  7. With the Footer Nav still selected in the HTML, open the Properties inspector. Click Play to preview it in HTML.
  8. Note: In the Properties inspector, you can also change the size of the Footer Nav.
  9. Open the HTML document in your browser of choice. The Footer Nav will look exactly as in the preview.

Note: Because of the patent lawsuit between Eolas and Microsoft, Microsoft may be forced to make some significant changes to the Internet Explorer browser. At the time of writing this article things are still in flux and Dreamweaver creates an HTML output the way things used to be. After integrating a Flash Element into your page, I recommend updating the page for deployment the way you should update any other page. You can find out about the techniques of doing so in the Active Content Developer Center.

Inserting the Footer Nav Flash Element in a page using Dreamweaver MX 2004

Figure 3. Inserting the Footer Nav Flash Element in a page using Dreamweaver MX 2004

That’s it—you took an existing Flash component and turned it into a Flash element that you can easily insert into any website. Now you too can be a Dreamweaver Extension developer.